<!DOCTYPE html><html lang="zh-tw"><head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6269;&#x5C55; | ECMAScript 6&#x5165;&#x95E8;</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.4.3">
        <meta name="author" content="&#x5927;&#x9F3B;&#x5B50;">
        
        <meta name="HandheldFriendly" content="true">
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://wohugb.gitbooks.io/ecmascript-6/content/gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="https://gstatic.gitbook.com/images/b1c4c86ca817a71628d2debe73be9a64.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="static/css/style.css">
    
        
        <link rel="stylesheet" href="static/css/website.css">
        
    
    

        
    
    
    <link rel="next" href="number.html">
    
    
    <link rel="prev" href="destructuring.html">
    

        
    
<style>
    .book .book-summary .book-search,
    .book .book-summary ul.summary {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        bottom: auto;
    }
    .book-summary {
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        display: flex;
        flex-direction: column;
        -webkit-box-orient: vertical;
        -webkit-box-direction: normal;
        overflow-y: auto;
    }
    .book-summary > nav {
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-y: overlay;
    }
    .gl-wrapper {
        margin: 0;
        display: block;
        padding: 0;
        position: relative;
        line-height: 15px;
        background: #fafafa;
    }
    .gl-wrapper:before {
        background: -webkit-linear-gradient(to bottom, rgba(250,250,250,0) 0%, #fafafa 100%);
        background: -moz-linear-gradient(to bottom, rgba(250,250,250,0) 0%, #fafafa 100%);
        top: -24px;
        width: 100%;
        height: 24px;
        content: "";
        display: block;
        position: absolute;
        background: linear-gradient(to bottom, rgba(250,250,250,0) 0%, #fafafa 100%);
    }
    .book.color-theme-1 .gl-wrapper {
        background: #121212;
    }
    .book.color-theme-1 .gl-wrapper:before {
        background: -webkit-linear-gradient(to bottom, rgba(18,18,18,0) 0%, #121212 100%);
        background: -moz-linear-gradient(to bottom, rgba(18,18,18,0) 0%, #121212 100%);
        background: linear-gradient(to bottom, rgba(18,18,18,0) 0%, #121212 100%);
    }
    .book.color-theme-2 .gl-wrapper {
        background: #2e3243;
    }
    .book.color-theme-2 .gl-wrapper:before {
        background: -webkit-linear-gradient(to bottom, rgba(46,50,67,0) 0%, #2e3243 100%);
        background: -moz-linear-gradient(to bottom, rgba(46,50,67,0) 0%, #2e3243 100%);
        background: linear-gradient(to bottom, rgba(46,50,67,0) 0%, #2e3243 100%);
    }
    .gl-wrapper .gitbook-link {
        display: -webkit-box;
        display: -moz-box;
        display: -ms-flexbox;
        display: -webkit-flex;
        color: #9DAAB6;
        margin: 16px;
        display: flex;
        padding: 0;
        align-items: center;
        margin-left: 32px;
        padding-top: 8px;
        padding-left: 16px;
        border-radius: 3px;
        padding-right: 16px;
        padding-bottom: 8px;
        text-decoration: none;
        background-color: #E6ECF1;
        -webkit-box-align: center;
    }
    .gl-wrapper .tm-logo {
        margin: 0;
        display: block;
        padding: 0;
        font-size: 40px;
    }
    .gl-wrapper .tm-content {
        flex: 1;
        margin: 0;
        display: block;
        padding: 0;
        padding-left: 16px;
    }
    .gl-wrapper .tm-content .container {
        margin: 0;
        display: block;
        padding: 0;
    }
    .gl-wrapper .tm-content .tm-container .tm-text {
        font-size: 12px;
        font-family: "Roboto", sans-serif;
        font-weight: 400;
        line-height: 1.625;
    }
</style></head>
    <body>
        
        
    <div class="book" data-level="4" data-basepath=".." data-revision="Sun Oct 25 2015 02:52:03 GMT+0000 (UTC)">
    

<div class="book-summary">
    <div class="book-search" role="search">
        <input type="text" placeholder="&#x8F38;&#x5165;&#x4E26;&#x641C;&#x5C0B;" class="form-control">
    </div>
    <nav role="navigation">
        <ul class="summary">
            
            
            
                
                <li>
                    <a href="javascript:;" target="blank" class="custom-link">ECMAScript 6&#x5165;&#x95E8;</a>
                </li>
            
            

            
            <li class="divider"></li>
            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="index.html">
                
                        <i class="fa fa-check"></i>
                        
                        &#x524D;&#x8A00;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="docs/intro.html">
            
                
                    <a href="intro.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        &#x7B80;&#x4ECB;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2" data-path="docs/let.html">
            
                
                    <a href="let.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        let&#x548C;const&#x547D;&#x4EE4;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3" data-path="docs/destructuring.html">
            
                
                    <a href="destructuring.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        &#x53D8;&#x91CF;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="4" data-path="docs/string.html">
            
                
                    <a href="">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        &#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5" data-path="docs/number.html">
            
                
                    <a href="number.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        &#x6570;&#x503C;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6" data-path="docs/array.html">
            
                
                    <a href="array.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        &#x6570;&#x7EC4;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7" data-path="docs/object.html">
            
                
                    <a href="object.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        &#x5BF9;&#x8C61;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="docs/function.html">
            
                
                    <a href="function.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        &#x51FD;&#x6570;&#x7684;&#x6269;&#x5C55;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="docs/set-map.html">
            
                
                    <a href="set-map.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        Set&#x548C;Map&#x6570;&#x636E;&#x7ED3;&#x6784;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10" data-path="docs/iterator.html">
            
                
                    <a href="iterator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Iterator&#x548C;for...of&#x5FAA;&#x73AF;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11" data-path="docs/generator.html">
            
                
                    <a href="generator.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        Generator &#x51FD;&#x6570;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12" data-path="docs/promise.html">
            
                
                    <a href="promise.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.</b>
                        
                        Promise&#x5BF9;&#x8C61;
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="13" data-path="docs/class.html">
            
                
                    <a href="class.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>13.</b>
                        
                        Class&#x548C;Module
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="14" data-path="docs/reference.html">
            
                
                    <a href="reference.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>14.</b>
                        
                        &#x53C2;&#x8003;&#x94FE;&#x63A5;
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            
            
        </ul>
    </nav>

<div class="gl-wrapper">
    <a class="gitbook-link" href="javascript:;" target="blank">
        <div class="tm-logo">
            <svg preserveaspectratio="xMidYMid meet" height="1em" width="1em" fill="currentColor" viewbox="0 0 1067 769" xmlns="http://www.w3.org/2000/svg" stroke="none" class="icon-7f6730be--text-3f89f380"><g><path d="M480.026 640.677c17.205 0 31.2 13.997 31.2 31.194s-13.995 31.193-31.2 31.193c-17.197 0-31.193-13.996-31.193-31.193 0-17.197 13.996-31.194 31.193-31.194m489.93-193.226c-17.203 0-31.2-13.998-31.2-31.195 0-17.204 13.997-31.2 31.2-31.2 17.198 0 31.194 13.996 31.194 31.2 0 17.197-13.996 31.195-31.193 31.195m0-127.804c-53.269 0-96.609 43.34-96.609 96.609 0 10.373 1.723 20.702 5.123 30.741L559.328 616.879c-18.132-26.128-47.521-41.617-79.302-41.617-36.821 0-70.391 21.065-86.63 54.003L106.68 478.109c-30.288-15.927-52.965-65.817-50.56-111.223 1.248-23.687 9.438-42.071 21.897-49.17 7.916-4.493 17.436-4.099 27.526 1.188l1.916 1.01c75.96 40.022 324.6 170.981 335.063 175.844 16.157 7.47 25.14 10.5 52.659-2.547l513.958-267.3c7.53-2.844 16.315-10.062 16.315-21.023 0-15.205-15.72-21.199-15.765-21.199-29.218-14.018-74.163-35.054-117.987-55.57C798.033 84.26 691.861 34.547 645.23 10.132c-40.253-21.072-72.655-3.311-78.432.282l-11.227 5.555C345.727 119.743 64.898 258.826 48.911 268.553 20.278 285.973 2.547 320.679.252 363.768c-3.586 68.304 31.261 139.506 81.069 165.634l303.172 156.354c6.83 47.306 47.55 82.725 95.532 82.725 52.78 0 95.808-42.546 96.603-95.14L910.541 492.38c16.93 13.233 37.92 20.486 59.416 20.486 53.268 0 96.61-43.341 96.61-96.61s-43.342-96.61-96.61-96.61" fill-rule="evenodd"></path></g></svg>
        </div>
        <div class="tm-content">
            <div class="tm-container">
                <span class="tm-text">
                    Powered by <b>GitBook</b>
                </span>
            </div>
        </div>
    </a>
</div></div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    <a href="#" class="btn pull-left toggle-summary" aria-label="&#x76EE;&#x9304;"><i class="fa fa-align-justify"></i></a>
    <a href="#" class="btn pull-left toggle-search" aria-label="&#x641C;&#x5C0B;"><i class="fa fa-search"></i></a>
    
    <div id="font-settings-wrapper" class="dropdown pull-left">
        <a href="#" class="btn toggle-dropdown" aria-label="&#x5B57;&#x578B;&#x8A2D;&#x5B9A;"><i class="fa fa-font"></i>
        </a>
        <div class="dropdown-menu font-settings">
    <div class="dropdown-caret">
        <span class="caret-outer"></span>
        <span class="caret-inner"></span>
    </div>

    <div class="buttons">
        <button type="button" id="reduce-font-size" class="button size-2">A</button>
        <button type="button" id="enlarge-font-size" class="button size-2">A</button>
    </div>

    <div class="buttons font-family-list">
        <button type="button" data-font="0" class="button">&#x896F;&#x7DDA;&#x9AD4;</button>
        <button type="button" data-font="1" class="button">&#x7121;&#x896F;&#x7DDA;&#x9AD4;</button>
    </div>

    <div class="buttons color-theme-list">
        <button type="button" id="color-theme-preview-0" class="button size-3" data-theme="0">&#x767D;&#x8272;</button>
        <button type="button" id="color-theme-preview-1" class="button size-3" data-theme="1">&#x68D5;&#x8910;&#x8272;</button>
        <button type="button" id="color-theme-preview-2" class="button size-3" data-theme="2">&#x591C;&#x9593;</button>
    </div>
</div>

    </div>

    <!-- Actions Right -->
    
    <div class="dropdown pull-right">
        <a href="#" class="btn toggle-dropdown" aria-label="&#x5206;&#x4EAB;"><i class="fa fa-share-alt"></i>
        </a>
        <div class="dropdown-menu font-settings dropdown-left">
            <div class="dropdown-caret">
                <span class="caret-outer"></span>
                <span class="caret-inner"></span>
            </div>
            <div class="buttons">
                <button type="button" data-sharing="twitter" class="button">
                    &#x5206;&#x4EAB;&#x5230; Twitter
                </button>
                <button type="button" data-sharing="google-plus" class="button">
                    &#x5206;&#x4EAB;&#x5230; Google
                </button>
                <button type="button" data-sharing="facebook" class="button">
                    &#x5206;&#x4EAB;&#x5230; Facebook
                </button>
                <button type="button" data-sharing="weibo" class="button">
                    &#x5206;&#x4EAB;&#x5230; Weibo
                </button>
                <button type="button" data-sharing="instapaper" class="button">
                    &#x5206;&#x4EAB;&#x5230; Instapaper
                </button>
            </div>
        </div>
    </div>
    

    
    <a href="#" target="_blank" class="btn pull-right google-plus-sharing-link sharing-link" data-sharing="google-plus" aria-label="Google"><i class="fa fa-google-plus"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right facebook-sharing-link sharing-link" data-sharing="facebook" aria-label="Facebook"><i class="fa fa-facebook"></i></a>
    
    
    <a href="#" target="_blank" class="btn pull-right twitter-sharing-link sharing-link" data-sharing="twitter" aria-label="Twitter"><i class="fa fa-twitter"></i></a>
    
    
    


    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="index.html">ECMAScript 6&#x5165;&#x95E8;</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%89%A9%E5%B1%95">&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6269;&#x5C55;</h1>
<p>ES6&#x52A0;&#x5F3A;&#x4E86;&#x5BF9;Unicode&#x7684;&#x652F;&#x6301;&#xFF0C;&#x5E76;&#x4E14;&#x6269;&#x5C55;&#x4E86;&#x5B57;&#x7B26;&#x4E32;&#x5BF9;&#x8C61;&#x3002;</p>
<h2 id="codepointat">codePointAt()</h2>
<p>JavaScript&#x5185;&#x90E8;&#xFF0C;&#x5B57;&#x7B26;&#x4EE5;UTF-16&#x7684;&#x683C;&#x5F0F;&#x50A8;&#x5B58;&#xFF0C;&#x6BCF;&#x4E2A;&#x5B57;&#x7B26;&#x56FA;&#x5B9A;&#x4E3A;2&#x4E2A;&#x5B57;&#x8282;&#x3002;&#x5BF9;&#x4E8E;&#x90A3;&#x4E9B;&#x9700;&#x8981;4&#x4E2A;&#x5B57;&#x8282;&#x50A8;&#x5B58;&#x7684;&#x5B57;&#x7B26;&#xFF08;Unicode&#x7801;&#x70B9;&#x5927;&#x4E8E;0xFFFF&#x7684;&#x5B57;&#x7B26;&#xFF09;&#xFF0C;JavaScript&#x4F1A;&#x8BA4;&#x4E3A;&#x5B83;&#x4EEC;&#x662F;&#x4E24;&#x4E2A;&#x5B57;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;&#x20BB7;&quot;</span>;

s.length <span class="hljs-comment">// 2</span>
s.charAt(<span class="hljs-number">0</span>) <span class="hljs-comment">// &apos;&apos;</span>
s.charAt(<span class="hljs-number">1</span>)    <span class="hljs-comment">// &apos;&apos;</span>
s.charCodeAt(<span class="hljs-number">0</span>) <span class="hljs-comment">// 55362        </span>
s.charCodeAt(<span class="hljs-number">1</span>) <span class="hljs-comment">// 57271</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6C49;&#x5B57;&#x201C;&#x20BB7;&#x201D;&#x7684;&#x7801;&#x70B9;&#x662F;0x20BB7&#xFF0C;UTF-16&#x7F16;&#x7801;&#x4E3A;0xD842 0xDFB7&#xFF08;&#x5341;&#x8FDB;&#x5236;&#x4E3A;55362 57271&#xFF09;&#xFF0C;&#x9700;&#x8981;4&#x4E2A;&#x5B57;&#x8282;&#x50A8;&#x5B58;&#x3002;&#x5BF9;&#x4E8E;&#x8FD9;&#x79CD;4&#x4E2A;&#x5B57;&#x8282;&#x7684;&#x5B57;&#x7B26;&#xFF0C;JavaScript&#x4E0D;&#x80FD;&#x6B63;&#x786E;&#x5904;&#x7406;&#xFF0C;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;&#x4F1A;&#x8BEF;&#x5224;&#x4E3A;2&#xFF0C;&#x800C;&#x4E14;charAt&#x65B9;&#x6CD5;&#x65E0;&#x6CD5;&#x8BFB;&#x53D6;&#x5B57;&#x7B26;&#xFF0C;charCodeAt&#x65B9;&#x6CD5;&#x53EA;&#x80FD;&#x5206;&#x522B;&#x8FD4;&#x56DE;&#x524D;&#x4E24;&#x4E2A;&#x5B57;&#x8282;&#x548C;&#x540E;&#x4E24;&#x4E2A;&#x5B57;&#x8282;&#x7684;&#x503C;&#x3002;</p>
<p>ES6&#x63D0;&#x4F9B;&#x4E86;codePointAt&#x65B9;&#x6CD5;&#xFF0C;&#x80FD;&#x591F;&#x6B63;&#x786E;&#x5904;&#x7406;4&#x4E2A;&#x5B57;&#x8282;&#x50A8;&#x5B58;&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x7684;&#x7801;&#x70B9;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;&#x20BB7;a&quot;</span>;

s.codePointAt(<span class="hljs-number">0</span>) <span class="hljs-comment">// 134071</span>
s.codePointAt(<span class="hljs-number">1</span>) <span class="hljs-comment">// 57271</span>

s.charCodeAt(<span class="hljs-number">2</span>) <span class="hljs-comment">// 97</span>
</code></pre>
<p>codePointAt&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x662F;&#x5B57;&#x7B26;&#x5728;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x4F4D;&#x7F6E;&#xFF08;&#x4ECE;0&#x5F00;&#x59CB;&#xFF09;&#x3002;&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;JavaScript&#x5C06;&#x201C;&#x20BB7;a&#x201D;&#x89C6;&#x4E3A;&#x4E09;&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;codePointAt&#x65B9;&#x6CD5;&#x5728;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E0A;&#xFF0C;&#x6B63;&#x786E;&#x5730;&#x8BC6;&#x522B;&#x4E86;&#x201C;&#x20BB7;&#x201D;&#xFF0C;&#x8FD4;&#x56DE;&#x4E86;&#x5B83;&#x7684;&#x5341;&#x8FDB;&#x5236;&#x7801;&#x70B9;134071&#xFF08;&#x5373;&#x5341;&#x516D;&#x8FDB;&#x5236;&#x7684;20BB7&#xFF09;&#x3002;&#x5728;&#x7B2C;&#x4E8C;&#x4E2A;&#x5B57;&#x7B26;&#xFF08;&#x5373;&#x201C;&#x20BB7;&#x201D;&#x7684;&#x540E;&#x4E24;&#x4E2A;&#x5B57;&#x8282;&#xFF09;&#x548C;&#x7B2C;&#x4E09;&#x4E2A;&#x5B57;&#x7B26;&#x201C;a&#x201D;&#x4E0A;&#xFF0C;codePointAt&#x65B9;&#x6CD5;&#x7684;&#x7ED3;&#x679C;&#x4E0E;charCodeAt&#x65B9;&#x6CD5;&#x76F8;&#x540C;&#x3002;</p>
<p>&#x603B;&#x4E4B;&#xFF0C;codePointAt&#x65B9;&#x6CD5;&#x4F1A;&#x6B63;&#x786E;&#x8FD4;&#x56DE;&#x56DB;&#x5B57;&#x8282;&#x7684;UTF-16&#x5B57;&#x7B26;&#x7684;&#x7801;&#x70B9;&#x3002;&#x5BF9;&#x4E8E;&#x90A3;&#x4E9B;&#x4E24;&#x4E2A;&#x5B57;&#x8282;&#x50A8;&#x5B58;&#x7684;&#x5E38;&#x89C4;&#x5B57;&#x7B26;&#xFF0C;&#x5B83;&#x7684;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x4E0E;charCodeAt&#x65B9;&#x6CD5;&#x76F8;&#x540C;&#x3002;</p>
<p>codePointAt&#x65B9;&#x6CD5;&#x662F;&#x6D4B;&#x8BD5;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x7531;&#x4E24;&#x4E2A;&#x5B57;&#x8282;&#x8FD8;&#x662F;&#x7531;&#x56DB;&#x4E2A;&#x5B57;&#x8282;&#x7EC4;&#x6210;&#x7684;&#x6700;&#x7B80;&#x5355;&#x65B9;&#x6CD5;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">is32Bit</span>(<span class="hljs-params">c</span>) </span>{
    <span class="hljs-keyword">return</span> c.codePointAt(<span class="hljs-number">0</span>) &gt; <span class="hljs-number">0xFFFF</span>;
}

is32Bit(<span class="hljs-string">&quot;&#x20BB7;&quot;</span>) <span class="hljs-comment">// true</span>
is32Bit(<span class="hljs-string">&quot;a&quot;</span>) <span class="hljs-comment">// false</span>
</code></pre>
<h2 id="string-fromcodepoint">String.fromCodePoint()</h2>
<p>ES5&#x63D0;&#x4F9B;String.fromCharCode&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x4E8E;&#x4ECE;&#x7801;&#x70B9;&#x8FD4;&#x56DE;&#x5BF9;&#x5E94;&#x5B57;&#x7B26;&#xFF0C;&#x4F46;&#x662F;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x4E0D;&#x80FD;&#x8BC6;&#x522B;&#x8F85;&#x52A9;&#x5E73;&#x9762;&#x7684;&#x5B57;&#x7B26;&#xFF08;&#x7F16;&#x53F7;&#x5927;&#x4E8E;0xFFFF&#xFF09;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-built_in">String</span>.fromCharCode(<span class="hljs-number">0x20BB7</span>)
<span class="hljs-comment">// &quot;&#xBB7;&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x6700;&#x540E;&#x8FD4;&#x56DE;&#x7801;&#x70B9;U+0BB7&#x5BF9;&#x5E94;&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x7801;&#x70B9;U+20BB7&#x5BF9;&#x5E94;&#x7684;&#x5B57;&#x7B26;&#x3002;</p>
<p>ES6&#x63D0;&#x4F9B;&#x4E86;String.fromCodePoint&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x8BC6;&#x522B;0xFFFF&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x5F25;&#x8865;&#x4E86;String.fromCharCode&#x65B9;&#x6CD5;&#x7684;&#x4E0D;&#x8DB3;&#x3002;&#x5728;&#x4F5C;&#x7528;&#x4E0A;&#xFF0C;&#x6B63;&#x597D;&#x4E0E;codePointAt&#x65B9;&#x6CD5;&#x76F8;&#x53CD;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-built_in">String</span>.fromCodePoint(<span class="hljs-number">0x20BB7</span>) 
<span class="hljs-comment">// &quot;&#x20BB7;&quot;</span>
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF0C;fromCodePoint&#x65B9;&#x6CD5;&#x5B9A;&#x4E49;&#x5728;String&#x5BF9;&#x8C61;&#x4E0A;&#xFF0C;&#x800C;codePointAt&#x65B9;&#x6CD5;&#x5B9A;&#x4E49;&#x5728;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x4E0A;&#x3002;</p>
<h2 id="at">at()</h2>
<p>ES5&#x63D0;&#x4F9B;String.prototype.charAt&#x65B9;&#x6CD5;&#xFF0C;&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;&#x7ED9;&#x5B9A;&#x4F4D;&#x7F6E;&#x7684;&#x5B57;&#x7B26;&#x3002;&#x8BE5;&#x65B9;&#x6CD5;&#x4E0D;&#x80FD;&#x8BC6;&#x522B;&#x7801;&#x70B9;&#x5927;&#x4E8E;0xFFFF&#x7684;&#x5B57;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&apos;&#x20BB7;&apos;</span>.charAt(<span class="hljs-number">0</span>)
<span class="hljs-comment">// &apos;\uD842&apos;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;charAt&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x7684;&#x662F;UTF-16&#x7F16;&#x7801;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#xFF0C;&#x5B9E;&#x9645;&#x4E0A;&#x662F;&#x65E0;&#x6CD5;&#x663E;&#x793A;&#x7684;&#x3002;</p>
<p>ES7&#x63D0;&#x4F9B;&#x4E86;at&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x8BC6;&#x522B;Unicode&#x7F16;&#x53F7;&#x5927;&#x4E8E;0xFFFF&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x8FD4;&#x56DE;&#x6B63;&#x786E;&#x7684;&#x5B57;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&apos;&#x20BB7;&apos;</span>.at(<span class="hljs-number">0</span>)
<span class="hljs-comment">// &apos;&#x20BB7;&apos;</span>
</code></pre>
<h2 id="%E5%AD%97%E7%AC%A6%E7%9A%84unicode%E8%A1%A8%E7%A4%BA%E6%B3%95">&#x5B57;&#x7B26;&#x7684;Unicode&#x8868;&#x793A;&#x6CD5;</h2>
<p>JavaScript&#x5141;&#x8BB8;&#x91C7;&#x7528;&#x201C;\uxxxx&#x201D;&#x5F62;&#x5F0F;&#x8868;&#x793A;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x5176;&#x4E2D;&#x201C;xxxx&#x201D;&#x8868;&#x793A;&#x5B57;&#x7B26;&#x7684;&#x7801;&#x70B9;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&quot;\u0061&quot;</span>
<span class="hljs-comment">// &quot;a&quot;</span>
</code></pre>
<p>&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x79CD;&#x8868;&#x793A;&#x6CD5;&#x53EA;&#x9650;&#x4E8E;\u0000&#x2014;&#x2014;\uFFFF&#x4E4B;&#x95F4;&#x7684;&#x5B57;&#x7B26;&#x3002;&#x8D85;&#x51FA;&#x8FD9;&#x4E2A;&#x8303;&#x56F4;&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x5FC5;&#x987B;&#x7528;&#x4E24;&#x4E2A;&#x53CC;&#x5B57;&#x8282;&#x7684;&#x5F62;&#x5F0F;&#x8868;&#x8FBE;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&quot;\uD842\uDFB7&quot;</span>
<span class="hljs-comment">// &quot;&#x20BB7;&quot;</span>

<span class="hljs-string">&quot;\u20BB7&quot;</span>
<span class="hljs-comment">// &quot; 7&quot;</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;&#x5982;&#x679C;&#x76F4;&#x63A5;&#x5728;&#x201C;\u&#x201D;&#x540E;&#x9762;&#x8DDF;&#x4E0A;&#x8D85;&#x8FC7;0xFFFF&#x7684;&#x6570;&#x503C;&#xFF08;&#x6BD4;&#x5982;\u20BB7&#xFF09;&#xFF0C;JavaScript&#x4F1A;&#x7406;&#x89E3;&#x6210;&#x201C;\u20BB+7&#x201D;&#x3002;&#x7531;&#x4E8E;\u20BB&#x662F;&#x4E00;&#x4E2A;&#x4E0D;&#x53EF;&#x6253;&#x5370;&#x5B57;&#x7B26;&#xFF0C;&#x6240;&#x4EE5;&#x53EA;&#x4F1A;&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x7A7A;&#x683C;&#xFF0C;&#x540E;&#x9762;&#x8DDF;&#x7740;&#x4E00;&#x4E2A;7&#x3002;</p>
<p>ES6&#x5BF9;&#x8FD9;&#x4E00;&#x70B9;&#x505A;&#x51FA;&#x4E86;&#x6539;&#x8FDB;&#xFF0C;&#x53EA;&#x8981;&#x5C06;&#x7801;&#x70B9;&#x653E;&#x5165;&#x5927;&#x62EC;&#x53F7;&#xFF0C;&#x5C31;&#x80FD;&#x6B63;&#x786E;&#x89E3;&#x8BFB;&#x8BE5;&#x5B57;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&quot;\u{20BB7}&quot;</span>
<span class="hljs-comment">// &quot;&#x20BB7;&quot;</span>

<span class="hljs-string">&quot;\u{41}\u{42}\u{43}&quot;</span>
<span class="hljs-comment">// &quot;ABC&quot;</span>
</code></pre>
<h2 id="%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84u%E4%BF%AE%E9%A5%B0%E7%AC%A6">&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x7684;u&#x4FEE;&#x9970;&#x7B26;</h2>
<p>ES6&#x5BF9;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x6DFB;&#x52A0;&#x4E86;u&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x7528;&#x6765;&#x6B63;&#x786E;&#x5904;&#x7406;&#x5927;&#x4E8E;\uFFFF&#x7684;Unicode&#x5B57;&#x7B26;&#x3002;</p>
<p><strong>&#xFF08;1&#xFF09;&#x70B9;&#x5B57;&#x7B26;</strong></p>
<p>&#x70B9;&#xFF08;.&#xFF09;&#x5B57;&#x7B26;&#x5728;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#xFF0C;&#x89E3;&#x91CA;&#x4E3A;&#x9664;&#x4E86;&#x6362;&#x884C;&#x4EE5;&#x5916;&#x7684;&#x4EFB;&#x610F;&#x5355;&#x4E2A;&#x5B57;&#x7B26;&#x3002;&#x5BF9;&#x4E8E;&#x7801;&#x70B9;&#x5927;&#x4E8E;0xFFFF&#x7684;Unicode&#x5B57;&#x7B26;&#xFF0C;&#x70B9;&#x5B57;&#x7B26;&#x4E0D;&#x80FD;&#x8BC6;&#x522B;&#xFF0C;&#x5FC5;&#x987B;&#x52A0;&#x4E0A;u&#x4FEE;&#x9970;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;&#x20BB7;&quot;</span>;

<span class="hljs-regexp">/^.$/</span>.test(s) <span class="hljs-comment">// false</span>
/^.$/u.test(s) <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x6DFB;&#x52A0;u&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x5C31;&#x4F1A;&#x8BA4;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#x4E3A;&#x4E24;&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x4ECE;&#x800C;&#x5339;&#x914D;&#x5931;&#x8D25;&#x3002;</p>
<p><strong>&#xFF08;2&#xFF09;Unicode&#x5B57;&#x7B26;&#x8868;&#x793A;&#x6CD5;</strong></p>
<p>ES6&#x65B0;&#x589E;&#x4E86;&#x4F7F;&#x7528;&#x5927;&#x62EC;&#x53F7;&#x8868;&#x793A;Unicode&#x5B57;&#x7B26;&#xFF0C;&#x8FD9;&#x79CD;&#x8868;&#x793A;&#x6CD5;&#x5728;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x4E2D;&#x5FC5;&#x987B;&#x52A0;&#x4E0A;u&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x624D;&#x80FD;&#x8BC6;&#x522B;&#x3002;</p>
<pre><code class="lang-javascript">
/\u{<span class="hljs-number">61</span>}/.test(<span class="hljs-string">&apos;a&apos;</span>) <span class="hljs-comment">// false</span>
/\u{<span class="hljs-number">61</span>}/u.test(<span class="hljs-string">&apos;a&apos;</span>) <span class="hljs-comment">// true</span>
/\u{<span class="hljs-number">20</span>BB7}/u.test(<span class="hljs-string">&apos;&#x20BB7;&apos;</span>) <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;&#x5982;&#x679C;&#x4E0D;&#x52A0;u&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x65E0;&#x6CD5;&#x8BC6;&#x522B;<code>\u{61}</code>&#x8FD9;&#x79CD;&#x8868;&#x793A;&#x6CD5;&#xFF0C;&#x53EA;&#x4F1A;&#x8BA4;&#x4E3A;&#x8FD9;&#x5339;&#x914D;61&#x4E2A;&#x8FDE;&#x7EED;&#x7684;u&#x3002;</p>
<p><strong>&#xFF08;3&#xFF09;&#x91CF;&#x8BCD;</strong></p>
<p>&#x4F7F;&#x7528;u&#x4FEE;&#x9970;&#x7B26;&#x540E;&#xFF0C;&#x6240;&#x6709;&#x91CF;&#x8BCD;&#x90FD;&#x4F1A;&#x6B63;&#x786E;&#x8BC6;&#x522B;&#x5927;&#x4E8E;&#x7801;&#x70B9;&#x5927;&#x4E8E;0xFFFF&#x7684;Unicode&#x5B57;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
/a{<span class="hljs-number">2</span>}/.test(<span class="hljs-string">&apos;aa&apos;</span>) <span class="hljs-comment">// true</span>
/a{<span class="hljs-number">2</span>}/u.test(<span class="hljs-string">&apos;aa&apos;</span>) <span class="hljs-comment">// true</span>
/&#x20BB7;{<span class="hljs-number">2</span>}/.test(<span class="hljs-string">&apos;&#x20BB7;&#x20BB7;&apos;</span>) <span class="hljs-comment">// false</span>
/&#x20BB7;{<span class="hljs-number">2</span>}/u.test(<span class="hljs-string">&apos;&#x20BB7;&#x20BB7;&apos;</span>) <span class="hljs-comment">// true</span>
</code></pre>
<p><strong>&#xFF08;4&#xFF09;&#x9884;&#x5B9A;&#x4E49;&#x6A21;&#x5F0F;</strong></p>
<p>u&#x4FEE;&#x9970;&#x7B26;&#x4E5F;&#x5F71;&#x54CD;&#x5230;&#x9884;&#x5B9A;&#x4E49;&#x6A21;&#x5F0F;&#xFF0C;&#x80FD;&#x5426;&#x6B63;&#x786E;&#x8BC6;&#x522B;&#x7801;&#x70B9;&#x5927;&#x4E8E;0xFFFF&#x7684;Unicode&#x5B57;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
/^\S$/.test(<span class="hljs-string">&apos;&#x20BB7;&apos;</span>) <span class="hljs-comment">// false</span>
/^\S$/u.test(<span class="hljs-string">&apos;&#x20BB7;&apos;</span>)
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7684;<code>\S</code>&#x662F;&#x9884;&#x5B9A;&#x4E49;&#x6A21;&#x5F0F;&#xFF0C;&#x5339;&#x914D;&#x6240;&#x6709;&#x4E0D;&#x662F;&#x7A7A;&#x683C;&#x7684;&#x5B57;&#x7B26;&#x3002;&#x53EA;&#x6709;&#x52A0;&#x4E86;u&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x5B83;&#x624D;&#x80FD;&#x6B63;&#x786E;&#x5339;&#x914D;&#x7801;&#x70B9;&#x5927;&#x4E8E;0xFFFF&#x7684;Unicode&#x5B57;&#x7B26;&#x3002;</p>
<p>&#x5229;&#x7528;&#x8FD9;&#x4E00;&#x70B9;&#xFF0C;&#x53EF;&#x4EE5;&#x5199;&#x51FA;&#x4E00;&#x4E2A;&#x6B63;&#x786E;&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;&#x7684;&#x51FD;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">codePointLength</span>(<span class="hljs-params">text</span>) </span>{
    <span class="hljs-keyword">var</span> result = text.match(<span class="hljs-regexp">/[\s\S]/gu</span>);
    <span class="hljs-keyword">return</span> result ? result.length : <span class="hljs-number">0</span>;
}

<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;&#x20BB7;&#x20BB7;&quot;</span>;

s.length <span class="hljs-comment">// 4</span>
codePointLength(s) <span class="hljs-comment">// 2</span>
</code></pre>
<p><strong>&#xFF08;5&#xFF09;i&#x4FEE;&#x9970;&#x7B26;</strong></p>
<p>&#x6709;&#x4E9B;Unicode&#x5B57;&#x7B26;&#x7684;&#x7F16;&#x7801;&#x4E0D;&#x540C;&#xFF0C;&#x4F46;&#x662F;&#x5B57;&#x578B;&#x5F88;&#x76F8;&#x8FD1;&#xFF0C;&#x6BD4;&#x5982;&#xFF0C;\u004B&#x4E0E;\u212A&#x90FD;&#x662F;&#x5927;&#x5199;&#x7684;K&#x3002;</p>
<pre><code class="lang-javascript">
/[a-z]/i.test(<span class="hljs-string">&apos;\u212A&apos;</span>) <span class="hljs-comment">// false</span>
/[a-z]/iu.test(<span class="hljs-string">&apos;\u212A&apos;</span>) <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x4E0D;&#x52A0;u&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x5C31;&#x65E0;&#x6CD5;&#x8BC6;&#x522B;&#x975E;&#x89C4;&#x8303;&#x7684;K&#x5B57;&#x7B26;&#x3002;</p>
<h2 id="normalize">normalize()</h2>
<p>&#x4E3A;&#x4E86;&#x8868;&#x793A;&#x8BED;&#x8C03;&#x548C;&#x91CD;&#x97F3;&#x7B26;&#x53F7;&#xFF0C;Unicode&#x63D0;&#x4F9B;&#x4E86;&#x4E24;&#x79CD;&#x65B9;&#x6CD5;&#x3002;&#x4E00;&#x79CD;&#x662F;&#x76F4;&#x63A5;&#x63D0;&#x4F9B;&#x5E26;&#x91CD;&#x97F3;&#x7B26;&#x53F7;&#x7684;&#x5B57;&#x7B26;&#xFF0C;&#x6BD4;&#x5982;&#x1D1;&#xFF08;\u01D1&#xFF09;&#x3002;&#x53E6;&#x4E00;&#x79CD;&#x662F;&#x63D0;&#x4F9B;&#x5408;&#x6210;&#x7B26;&#x53F7;&#xFF08;combining character&#xFF09;&#xFF0C;&#x5373;&#x539F;&#x5B57;&#x7B26;&#x4E0E;&#x91CD;&#x97F3;&#x7B26;&#x53F7;&#x7684;&#x5408;&#x6210;&#xFF0C;&#x4E24;&#x4E2A;&#x5B57;&#x7B26;&#x5408;&#x6210;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x6BD4;&#x5982;O&#xFF08;\u004F&#xFF09;&#x548C;&#x2C7;&#xFF08;\u030C&#xFF09;&#x5408;&#x6210;&#x1D1;&#xFF08;\u004F\u030C&#xFF09;&#x3002;</p>
<p>&#x8FD9;&#x4E24;&#x79CD;&#x8868;&#x793A;&#x65B9;&#x6CD5;&#xFF0C;&#x5728;&#x89C6;&#x89C9;&#x548C;&#x8BED;&#x4E49;&#x4E0A;&#x90FD;&#x7B49;&#x4EF7;&#xFF0C;&#x4F46;&#x662F;JavaScript&#x4E0D;&#x80FD;&#x8BC6;&#x522B;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&apos;\u01D1&apos;</span>===<span class="hljs-string">&apos;\u004F\u030C&apos;</span> <span class="hljs-comment">//false</span>

<span class="hljs-string">&apos;\u01D1&apos;</span>.length <span class="hljs-comment">// 1</span>
<span class="hljs-string">&apos;\u004F\u030C&apos;</span>.length <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;JavaScript&#x5C06;&#x5408;&#x6210;&#x5B57;&#x7B26;&#x89C6;&#x4E3A;&#x4E24;&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x5BFC;&#x81F4;&#x4E24;&#x79CD;&#x8868;&#x793A;&#x65B9;&#x6CD5;&#x4E0D;&#x76F8;&#x7B49;&#x3002;</p>
<p>ES6&#x63D0;&#x4F9B;String.prototype.normalize()&#x65B9;&#x6CD5;&#xFF0C;&#x7528;&#x6765;&#x5C06;&#x5B57;&#x7B26;&#x7684;&#x4E0D;&#x540C;&#x8868;&#x793A;&#x65B9;&#x6CD5;&#x7EDF;&#x4E00;&#x4E3A;&#x540C;&#x6837;&#x7684;&#x5F62;&#x5F0F;&#xFF0C;&#x8FD9;&#x79F0;&#x4E3A;Unicode&#x6B63;&#x89C4;&#x5316;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&apos;\u01D1&apos;</span>.normalize() === <span class="hljs-string">&apos;\u004F\u030C&apos;</span>.normalize() 
<span class="hljs-comment">// true</span>
</code></pre>
<p>normalize&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x63A5;&#x53D7;&#x56DB;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
<ul>
<li>NFC&#xFF0C;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;&#xFF0C;&#x8868;&#x793A;&#x201C;&#x6807;&#x51C6;&#x7B49;&#x4EF7;&#x5408;&#x6210;&#x201D;&#xFF08;Normalization Form Canonical Composition&#xFF09;&#xFF0C;&#x8FD4;&#x56DE;&#x591A;&#x4E2A;&#x7B80;&#x5355;&#x5B57;&#x7B26;&#x7684;&#x5408;&#x6210;&#x5B57;&#x7B26;&#x3002;&#x6240;&#x8C13;&#x201C;&#x6807;&#x51C6;&#x7B49;&#x4EF7;&#x201D;&#x6307;&#x7684;&#x662F;&#x89C6;&#x89C9;&#x548C;&#x8BED;&#x4E49;&#x4E0A;&#x7684;&#x7B49;&#x4EF7;&#x3002;</li>
<li>NFD&#xFF0C;&#x8868;&#x793A;&#x201C;&#x6807;&#x51C6;&#x7B49;&#x4EF7;&#x5206;&#x89E3;&#x201D;&#xFF08;Normalization Form Canonical Decomposition&#xFF09;&#xFF0C;&#x5373;&#x5728;&#x6807;&#x51C6;&#x7B49;&#x4EF7;&#x7684;&#x524D;&#x63D0;&#x4E0B;&#xFF0C;&#x8FD4;&#x56DE;&#x5408;&#x6210;&#x5B57;&#x7B26;&#x5206;&#x89E3;&#x7684;&#x591A;&#x4E2A;&#x7B80;&#x5355;&#x5B57;&#x7B26;&#x3002;</li>
<li>NFKC&#xFF0C;&#x8868;&#x793A;&#x201C;&#x517C;&#x5BB9;&#x7B49;&#x4EF7;&#x5408;&#x6210;&#x201D;&#xFF08;Normalization Form Compatibility Composition&#xFF09;&#xFF0C;&#x8FD4;&#x56DE;&#x5408;&#x6210;&#x5B57;&#x7B26;&#x3002;&#x6240;&#x8C13;&#x201C;&#x517C;&#x5BB9;&#x7B49;&#x4EF7;&#x201D;&#x6307;&#x7684;&#x662F;&#x8BED;&#x4E49;&#x4E0A;&#x5B58;&#x5728;&#x7B49;&#x4EF7;&#xFF0C;&#x4F46;&#x89C6;&#x89C9;&#x4E0A;&#x4E0D;&#x7B49;&#x4EF7;&#xFF0C;&#x6BD4;&#x5982;&#x201C;&#x56CD;&#x201D;&#x548C;&#x201C;&#x559C;&#x559C;&#x201D;&#x3002;</li>
<li>NFKD&#xFF0C;&#x8868;&#x793A;&#x201C;&#x517C;&#x5BB9;&#x7B49;&#x4EF7;&#x5206;&#x89E3;&#x201D;&#xFF08;Normalization Form Compatibility Decomposition&#xFF09;&#xFF0C;&#x5373;&#x5728;&#x517C;&#x5BB9;&#x7B49;&#x4EF7;&#x7684;&#x524D;&#x63D0;&#x4E0B;&#xFF0C;&#x8FD4;&#x56DE;&#x5408;&#x6210;&#x5B57;&#x7B26;&#x5206;&#x89E3;&#x7684;&#x591A;&#x4E2A;&#x7B80;&#x5355;&#x5B57;&#x7B26;&#x3002;</li>
</ul>
<pre><code class="lang-javascript">
<span class="hljs-string">&apos;\u004F\u030C&apos;</span>.normalize(NFC).length <span class="hljs-comment">// 1</span>
<span class="hljs-string">&apos;\u004F\u030C&apos;</span>.normalize(NFD).length <span class="hljs-comment">// 2</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;NFC&#x53C2;&#x6570;&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x7684;&#x5408;&#x6210;&#x5F62;&#x5F0F;&#xFF0C;NFD&#x53C2;&#x6570;&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x7684;&#x5206;&#x89E3;&#x5F62;&#x5F0F;&#x3002;</p>
<p>&#x4E0D;&#x8FC7;&#xFF0C;normalize&#x65B9;&#x6CD5;&#x76EE;&#x524D;&#x4E0D;&#x80FD;&#x8BC6;&#x522B;&#x4E09;&#x4E2A;&#x6216;&#x4E09;&#x4E2A;&#x4EE5;&#x4E0A;&#x5B57;&#x7B26;&#x7684;&#x5408;&#x6210;&#x3002;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8FD8;&#x662F;&#x53EA;&#x80FD;&#x4F7F;&#x7528;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x901A;&#x8FC7;Unicode&#x7F16;&#x53F7;&#x533A;&#x95F4;&#x5224;&#x65AD;&#x3002;</p>
<h2 id="contains-startswith-endswith">contains(), startsWith(), endsWith()</h2>
<p>&#x4F20;&#x7EDF;&#x4E0A;&#xFF0C;JavaScript&#x53EA;&#x6709;indexOf&#x65B9;&#x6CD5;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x786E;&#x5B9A;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x5426;&#x5305;&#x542B;&#x5728;&#x53E6;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x3002;ES6&#x53C8;&#x63D0;&#x4F9B;&#x4E86;&#x4E09;&#x79CD;&#x65B0;&#x65B9;&#x6CD5;&#x3002;</p>
<ul>
<li><strong>contains()</strong>&#xFF1A;&#x8FD4;&#x56DE;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x8868;&#x793A;&#x662F;&#x5426;&#x627E;&#x5230;&#x4E86;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x3002;</li>
<li><strong>startsWith()</strong>&#xFF1A;&#x8FD4;&#x56DE;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x8868;&#x793A;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x5426;&#x5728;&#x6E90;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5934;&#x90E8;&#x3002;</li>
<li><strong>endsWith()</strong>&#xFF1A;&#x8FD4;&#x56DE;&#x5E03;&#x5C14;&#x503C;&#xFF0C;&#x8868;&#x793A;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x5426;&#x5728;&#x6E90;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5C3E;&#x90E8;&#x3002;</li>
</ul>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;Hello world!&quot;</span>;

s.startsWith(<span class="hljs-string">&quot;Hello&quot;</span>) <span class="hljs-comment">// true</span>
s.endsWith(<span class="hljs-string">&quot;!&quot;</span>) <span class="hljs-comment">// true</span>
s.contains(<span class="hljs-string">&quot;o&quot;</span>) <span class="hljs-comment">// true</span>
</code></pre>
<p>&#x8FD9;&#x4E09;&#x4E2A;&#x65B9;&#x6CD5;&#x90FD;&#x652F;&#x6301;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8868;&#x793A;&#x5F00;&#x59CB;&#x641C;&#x7D22;&#x7684;&#x4F4D;&#x7F6E;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;Hello world!&quot;</span>;

s.startsWith(<span class="hljs-string">&quot;o&quot;</span>, <span class="hljs-number">4</span>) <span class="hljs-comment">// true</span>
s.endsWith(<span class="hljs-string">&quot;o&quot;</span>, <span class="hljs-number">8</span>) <span class="hljs-comment">// true</span>
s.contains(<span class="hljs-string">&quot;o&quot;</span>, <span class="hljs-number">8</span>) <span class="hljs-comment">// false</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x8868;&#x793A;&#xFF0C;&#x4F7F;&#x7528;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;n&#x65F6;&#xFF0C;endsWith&#x7684;&#x884C;&#x4E3A;&#x4E0E;&#x5176;&#x4ED6;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x6709;&#x6240;&#x4E0D;&#x540C;&#x3002;&#x5B83;&#x9488;&#x5BF9;&#x524D;n&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x800C;&#x5176;&#x4ED6;&#x4E24;&#x4E2A;&#x65B9;&#x6CD5;&#x9488;&#x5BF9;&#x4ECE;&#x7B2C;n&#x4E2A;&#x4F4D;&#x7F6E;&#x76F4;&#x5230;&#x5B57;&#x7B26;&#x4E32;&#x7ED3;&#x675F;&#x3002;</p>
<h2 id="repeat">repeat()</h2>
<p>repeat()&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x8868;&#x793A;&#x5C06;&#x539F;&#x5B57;&#x7B26;&#x4E32;&#x91CD;&#x590D;n&#x6B21;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-string">&quot;x&quot;</span>.repeat(<span class="hljs-number">3</span>) <span class="hljs-comment">// &quot;xxx&quot;</span>
<span class="hljs-string">&quot;hello&quot;</span>.repeat(<span class="hljs-number">2</span>) <span class="hljs-comment">// &quot;hellohello&quot;</span>
</code></pre>
<h2 id="%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84y%E4%BF%AE%E9%A5%B0%E7%AC%A6">&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x7684;y&#x4FEE;&#x9970;&#x7B26;</h2>
<p>&#x9664;&#x4E86;u&#x4FEE;&#x9970;&#x7B26;&#xFF0C;ES6&#x8FD8;&#x4E3A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x6DFB;&#x52A0;&#x4E86;y&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x53EB;&#x505A;&#x201C;&#x7C98;&#x8FDE;&#x201D;&#xFF08;sticky&#xFF09;&#x4FEE;&#x9970;&#x7B26;&#x3002;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x4E0E;g&#x4FEE;&#x9970;&#x7B26;&#x7C7B;&#x4F3C;&#xFF0C;&#x4E5F;&#x662F;&#x5168;&#x5C40;&#x5339;&#x914D;&#xFF0C;&#x540E;&#x4E00;&#x6B21;&#x5339;&#x914D;&#x90FD;&#x4ECE;&#x4E0A;&#x4E00;&#x6B21;&#x5339;&#x914D;&#x6210;&#x529F;&#x7684;&#x4E0B;&#x4E00;&#x4E2A;&#x4F4D;&#x7F6E;&#x5F00;&#x59CB;&#xFF0C;&#x4E0D;&#x540C;&#x4E4B;&#x5904;&#x5728;&#x4E8E;&#xFF0C;g&#x4FEE;&#x9970;&#x7B26;&#x53EA;&#x786E;&#x4FDD;&#x5269;&#x4F59;&#x4F4D;&#x7F6E;&#x4E2D;&#x5B58;&#x5728;&#x5339;&#x914D;&#xFF0C;&#x800C;y&#x4FEE;&#x9970;&#x7B26;&#x786E;&#x4FDD;&#x5339;&#x914D;&#x5FC5;&#x987B;&#x4ECE;&#x5269;&#x4F59;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x4F4D;&#x7F6E;&#x5F00;&#x59CB;&#xFF0C;&#x8FD9;&#x4E5F;&#x5C31;&#x662F;&#x201C;&#x7C98;&#x8FDE;&#x201D;&#x7684;&#x6DB5;&#x4E49;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;aaa_aa_a&quot;</span>;
<span class="hljs-keyword">var</span> r1 = <span class="hljs-regexp">/a+/g</span>;
<span class="hljs-keyword">var</span> r2 = <span class="hljs-regexp">/a+/y</span>;

r1.exec(s) <span class="hljs-comment">// [&quot;aaa&quot;]</span>
r2.exec(s) <span class="hljs-comment">// [&quot;aaa&quot;]</span>

r1.exec(s) <span class="hljs-comment">// [&quot;aa&quot;]</span>
r2.exec(s) <span class="hljs-comment">// null</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x6709;&#x4E24;&#x4E2A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x4E00;&#x4E2A;&#x4F7F;&#x7528;g&#x4FEE;&#x9970;&#x7B26;&#xFF0C;&#x53E6;&#x4E00;&#x4E2A;&#x4F7F;&#x7528;y&#x4FEE;&#x9970;&#x7B26;&#x3002;&#x8FD9;&#x4E24;&#x4E2A;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x5404;&#x6267;&#x884C;&#x4E86;&#x4E24;&#x6B21;&#xFF0C;&#x7B2C;&#x4E00;&#x6B21;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4E24;&#x8005;&#x884C;&#x4E3A;&#x76F8;&#x540C;&#xFF0C;&#x5269;&#x4F59;&#x5B57;&#x7B26;&#x4E32;&#x90FD;&#x662F;&#x201C;_aa_a&#x201D;&#x3002;&#x7531;&#x4E8E;g&#x4FEE;&#x9970;&#x6CA1;&#x6709;&#x4F4D;&#x7F6E;&#x8981;&#x6C42;&#xFF0C;&#x6240;&#x4EE5;&#x7B2C;&#x4E8C;&#x6B21;&#x6267;&#x884C;&#x4F1A;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF0C;&#x800C;y&#x4FEE;&#x9970;&#x7B26;&#x8981;&#x6C42;&#x5339;&#x914D;&#x5FC5;&#x987B;&#x4ECE;&#x5934;&#x90E8;&#x5F00;&#x59CB;&#xFF0C;&#x6240;&#x4EE5;&#x8FD4;&#x56DE;null&#x3002;</p>
<p>&#x5982;&#x679C;&#x6539;&#x4E00;&#x4E0B;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x4FDD;&#x8BC1;&#x6BCF;&#x6B21;&#x90FD;&#x80FD;&#x5934;&#x90E8;&#x5339;&#x914D;&#xFF0C;y&#x4FEE;&#x9970;&#x7B26;&#x5C31;&#x4F1A;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x4E86;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> s = <span class="hljs-string">&quot;aaa_aa_a&quot;</span>;
<span class="hljs-keyword">var</span> r = <span class="hljs-regexp">/a+_/y</span>;

r.exec(s) <span class="hljs-comment">// [&quot;aaa_&quot;]</span>
r.exec(s) <span class="hljs-comment">// [&quot;aa_&quot;]</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x6BCF;&#x6B21;&#x5339;&#x914D;&#xFF0C;&#x90FD;&#x662F;&#x4ECE;&#x5269;&#x4F59;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5934;&#x90E8;&#x5F00;&#x59CB;&#x3002;</p>
<p>&#x8FDB;&#x4E00;&#x6B65;&#x8BF4;&#xFF0C;y&#x4FEE;&#x9970;&#x7B26;&#x53F7;&#x9690;&#x542B;&#x4E86;&#x5934;&#x90E8;&#x5339;&#x914D;&#x7684;&#x6807;&#x5FD7;&#x2C6;&#x3002;</p>
<pre><code class="lang-javascript">
/b/y.exec(<span class="hljs-string">&quot;aba&quot;</span>)
<span class="hljs-comment">// null</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x7531;&#x4E8E;&#x4E0D;&#x80FD;&#x4FDD;&#x8BC1;&#x5934;&#x90E8;&#x5339;&#x914D;&#xFF0C;&#x6240;&#x4EE5;&#x8FD4;&#x56DE;null&#x3002;y&#x4FEE;&#x9970;&#x7B26;&#x7684;&#x8BBE;&#x8BA1;&#x672C;&#x610F;&#xFF0C;&#x5C31;&#x662F;&#x8BA9;&#x5934;&#x90E8;&#x5339;&#x914D;&#x7684;&#x6807;&#x5FD7;&#x2C6;&#x5728;&#x5168;&#x5C40;&#x5339;&#x914D;&#x4E2D;&#x90FD;&#x6709;&#x6548;&#x3002;</p>
<p>&#x4E0E;y&#x4FEE;&#x9970;&#x7B26;&#x76F8;&#x5339;&#x914D;&#xFF0C;ES6&#x7684;&#x6B63;&#x5219;&#x5BF9;&#x8C61;&#x591A;&#x4E86;sticky&#x5C5E;&#x6027;&#xFF0C;&#x8868;&#x793A;&#x662F;&#x5426;&#x8BBE;&#x7F6E;&#x4E86;y&#x4FEE;&#x9970;&#x7B26;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> r = <span class="hljs-regexp">/hello\d/y</span>;
r.sticky <span class="hljs-comment">// true</span>
</code></pre>
<h2 id="%E6%A8%A1%E6%9D%BF%E5%AD%97%E7%AC%A6%E4%B8%B2">&#x6A21;&#x677F;&#x5B57;&#x7B26;&#x4E32;</h2>
<p>&#x6A21;&#x677F;&#x5B57;&#x7B26;&#x4E32;&#xFF08;template string&#xFF09;&#x662F;&#x589E;&#x5F3A;&#x7248;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x7528;&#x53CD;&#x5F15;&#x53F7;&#xFF08;`&#xFF09;&#x6807;&#x8BC6;&#x3002;&#x5B83;&#x53EF;&#x4EE5;&#x5F53;&#x4F5C;&#x666E;&#x901A;&#x5B57;&#x7B26;&#x4E32;&#x4F7F;&#x7528;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x5B9A;&#x4E49;&#x591A;&#x884C;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x6216;&#x8005;&#x5728;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x5D4C;&#x5165;&#x53D8;&#x91CF;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-comment">// &#x666E;&#x901A;&#x5B57;&#x7B26;&#x4E32;</span>
<span class="hljs-string">`In JavaScript &apos;\n&apos; is a line-feed.`</span>

<span class="hljs-comment">// &#x591A;&#x884C;&#x5B57;&#x7B26;&#x4E32;</span>
<span class="hljs-string">`In JavaScript this is
 not legal.`</span>

<span class="hljs-comment">// &#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x5D4C;&#x5165;&#x53D8;&#x91CF;</span>
<span class="hljs-keyword">var</span> name = <span class="hljs-string">&quot;Bob&quot;</span>, time = <span class="hljs-string">&quot;today&quot;</span>;
<span class="hljs-string">`Hello <span class="hljs-subst">${name}</span>, how are you <span class="hljs-subst">${time}</span>?`</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x90FD;&#x662F;&#x7528;&#x53CD;&#x5F15;&#x53F7;&#x8868;&#x793A;&#x3002;&#x5982;&#x679C;&#x5728;&#x6A21;&#x677F;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x5D4C;&#x5165;&#x53D8;&#x91CF;&#xFF0C;&#x9700;&#x8981;&#x5C06;&#x53D8;&#x91CF;&#x540D;&#x5199;&#x5728;<code>${}</code>&#x4E4B;&#x4E2D;&#x3002;</p>
<p>&#x5927;&#x62EC;&#x53F7;&#x5185;&#x90E8;&#x53EF;&#x4EE5;&#x8FDB;&#x884C;&#x8FD0;&#x7B97;&#xFF0C;&#x4EE5;&#x53CA;&#x5F15;&#x7528;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> x = <span class="hljs-number">1</span>;
<span class="hljs-keyword">var</span> y = <span class="hljs-number">2</span>;

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${x}</span> + <span class="hljs-subst">${y}</span> = <span class="hljs-subst">${x+y}</span>`</span>) 
<span class="hljs-comment">// &quot;1 + 2 = 3&quot;</span>

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${x}</span> + <span class="hljs-subst">${y*2}</span> = <span class="hljs-subst">${x+y*2}</span>`</span>) 
<span class="hljs-comment">// &quot;1 + 4 = 5&quot;</span>

<span class="hljs-keyword">var</span> obj = {x: <span class="hljs-number">1</span>, y: <span class="hljs-number">2</span>};
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${obj.x + obj.y}</span>`</span>)
<span class="hljs-comment">// 3</span>
</code></pre>
<p>&#x6A21;&#x677F;&#x5B57;&#x7B26;&#x4E32;&#x4F7F;&#x5F97;&#x5B57;&#x7B26;&#x4E32;&#x4E0E;&#x53D8;&#x91CF;&#x7684;&#x7ED3;&#x5408;&#xFF0C;&#x53D8;&#x5F97;&#x5BB9;&#x6613;&#x3002;&#x4E0B;&#x9762;&#x662F;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;</p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">if</span> (x &gt; MAX) {
    <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">`Most <span class="hljs-subst">${MAX}</span> allowed: <span class="hljs-subst">${x}</span>!`</span>);
    <span class="hljs-comment">// &#x4F20;&#x7EDF;&#x5199;&#x6CD5;&#x4E3A;&apos;Most &apos;+MAX+&apos; allowed: &apos;+x+&apos;!&apos;</span>
}
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="destructuring.html" class="navigation navigation-prev " aria-label="Previous page: &#x53D8;&#x91CF;&#x7684;&#x89E3;&#x6784;&#x8D4B;&#x503C;"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="number.html" class="navigation navigation-next " aria-label="Next page: &#x6570;&#x503C;&#x7684;&#x6269;&#x5C55;"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="static/js/app.js"></script>

    
    <script src="static/js/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontSettings":{"theme":null,"family":"sans","size":2},"disqus":{"shortName":"git-book"}};
    gitbook.start(config);
});
</script>

        
    
    

</body></html>